package cn.myschool.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

/**
 * Service,Respotory,Componnet,Controller
 *
 * @author oldliu
 * @since 1.0
 */
@Controller
@RequestMapping("/hello")
public class HelloController {
    private String pageNo;

    @RequestMapping("/wenhao")
    public ModelAndView sayHi() {

        ModelAndView mv = new ModelAndView();
        mv.setViewName("/hello.jsp");// 加了  /，从项目根目录开始，否则从当前虚拟目录
        mv.addObject("msg", "大扎好，你是渣渣灰，现在是" + new Date());
        return mv;
    }

    @RequestMapping("/page")
    public ModelAndView page(@RequestParam(name = "p",required = false) String p) {
        if (p!= null)
            this.pageNo = p;

        ModelAndView mv = new ModelAndView();
        mv.setViewName("forward:/hello.jsp");// 加了  /，从项目根目录开始，否则从当前虚拟目录
        if (this.pageNo != null)
            mv.addObject("msg", " 当前页是" + Integer.parseInt(pageNo));
        else
            mv.addObject("msg", " 当前页是没");

        return mv;
    }
}
